//题目数据集。
Ext.define("ES.store.ItemsStore",{
    extend:"Ext.data.Store",
    model:"ES.model.ItemsModel",
    pageSize:20,
    remoteSort:true,
    autoLoad:false,
    proxy:{
        type:"ajax",
        url:"Item!list.action",
        reader:{
            type:"json",
            root:"dataSource.entityList",
            totalProperty:"dataSource.totalCounts"
        },
        listeners:{
            exception:function(proxy, resp, operation, opt){
                    Ext.MessageBox.show({
                        title:"远程异常",
                        msg:operation.getError(),
                        icon:Ext.MessageBox.ERROR,
                        buttons:Ext.Msg.OK
                    });
                }
        }
    },
     listeners:{
        //加载数据前。
        beforeload:function(store, operation){
            Ext.getBody().mask("正在加载数据，请稍后...");
            Ext.apply(store.proxy.extraParams,{
                ascProperty:"CatalogName",
                asc:false
            });
        },
        //加载数据。
        load:function(){
            Ext.getBody().unmask();
        },
        //更新数据。
        update:function(store, record){
            var currPage = store.currentPage;
            Ext.Ajax.request({
                url:"Item!update.action",
                params:{
                    itemID:record.get("itemID"),
                    content:record.get("content"),
                    typeID:record.get("typeID"),
                    catalogID:record.get("catalogID"),
                    sectionID:record.get("sectionID"),
                    difficulty:record.get("difficulty"),
                    createTime:record.get("createTime"),
                    orderNo:record.get("orderNo"),
                    
                    items:record.get("items"),
                    answers:record.get("answers")
                },
                method:"POST",
                success:function(){
                    store.removeAll();
                    store.loadPage(currPage);
                }
            });
        },
        //删除数据。
        remove:function(store, record){
            var currPage = store.currentPage;
            Ext.Ajax.request({
                   url:"Item!delete.action",
                   params:{
                        itemID:record.get("itemID")
                   },
                   method:"POST",
                   success:function(){
                    store.removeAll();
                    store.loadPage(currPage);
                 }
              });
        }
    }
})